<?php

namespace App\Http\Controllers;

use App\Traits\ApiResponse;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class ApiController extends Controller {

    use ApiResponse;

    /**
     * 检查用户权限
     * Author:poptser@foxmail.com
     * @param $userType
     * @param $userId
     * @return bool
     */
    public function checkUserType($userType, $userId){
        $position = DB::table("warehouse_personnel")
            ->where("uid","=",$userId)
            ->value("position");
        if($position == $userType){
            return false;
        }else{
            return true;
        }
    }

    /**
     * 返回用户信息
     * Author:poptser@foxmail.com
     * @param $message
     */
    public function returnErr($message){
        header('Access-Control-Allow-Origin:*');
        header('Content-Type:application/json');
        $data['status'] = $message;
        $data['code'] = 400;
        $data['message'] = $message;
        echo json_encode($data);
        exit;
    }
}